//
// Created by Martin on 2022/1/13.
//

#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

void dfs0(int x, int y, vector<string > &a)
{
    a[x][y] = '.';

    for (int dx = -1; dx <= 1 ; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
            int nx = x + dx;
            int ny = y + dy;
            if (0 <= nx && nx < a.size() && 0 <= ny && ny < a[0].size() && a[nx][ny] == 'W') dfs0(nx, ny, a);
        }
    }
}

/**
 * poj 2386
 */
int main()
{
    int N, M;
    cin >> N >> M;
    if (N <= 0 || M <= 0) {
        cout << 0 << endl;
        return -1;
    }

    vector<string> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int res = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if ('W' == a[i][j]) {
                dfs0(i, j, a);
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

// sum是前i项得到的和
bool dfs(int i, int sum, int n, int a[], int k)
{
    if (i == n) return sum == k;

    // 不加上a[i]
    if (dfs(i + 1, sum, n, a, k)) return true;

    // 加上a[i]
    if (dfs(i + 1, sum + a[i], n, a, k)) return true;

    return false;
}

/**
 * 给定整数a1,a2,...,an, 判断是否可以从中选出若干数，使它们的和恰好为k
 */
int main_dfs1()
{
    int n, k, *a;
    scanf("%d", &n);
    if (n <= 0) return -1;
    a = new int[n];

    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    scanf("%d", &k);

    bool res = dfs(0, 0, n, a, k);
    if (res) printf("Yes\n");
    else printf("No\n");

    delete[] a;
    return 0;
}